import React, { useEffect } from "react";
import JSEncrypt from "./jsencrypt.js";

function App() {
  useEffect(() => {
    // // 创建 JSEncrypt 实例，指定密钥大小为 1024 位
    const jsEncrypt = new JSEncrypt({ default_key_size: "2048" });
    // console.log(">>>>>>>>>>>JSEncrypt", jsEncrypt);

    // 加密使用的公钥
    const publicKey = `MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAueYOVz8u6zfx/fiVMSbkVAyOAhicUYEwT9V93Z1gWYSMU2fPVJaBOlGBfD0xZJ3blsFauhwl9yhWjJerHGS7tvLIDY2e3/3/9iNMmPym0RnfYe6r1tKgaHsA18v03SNHv7Pl665DeJM+fzPCdWmKJV+pmQ0yDEvXiY5mlWleGUIlQ70zE0DDoNQb95qSGWHd1rsIA0A8k4w+9QBRLFD9OM/OlH6X6h+Z3ItcJwLNlfvGmpEINOnHyqooRw4ywjrmsUDnn2hX1wT6NViD5Orba2ddKTb94S7ByKfzeZSBIR5tFjhZY5tAKUnnD3L4ODge6FdH17Zny5584EKzXUJiewIDAQAB`;

    // 解密使用的私钥
    const privateKey = `MIIEpAIBAAKCAQEAueYOVz8u6zfx/fiVMSbkVAyOAhicUYEwT9V93Z1gWYSMU2fPVJaBOlGBfD0xZJ3blsFauhwl9yhWjJerHGS7tvLIDY2e3/3/9iNMmPym0RnfYe6r1tKgaHsA18v03SNHv7Pl665DeJM+fzPCdWmKJV+pmQ0yDEvXiY5mlWleGUIlQ70zE0DDoNQb95qSGWHd1rsIA0A8k4w+9QBRLFD9OM/OlH6X6h+Z3ItcJwLNlfvGmpEINOnHyqooRw4ywjrmsUDnn2hX1wT6NViD5Orba2ddKTb94S7ByKfzeZSBIR5tFjhZY5tAKUnnD3L4ODge6FdH17Zny5584EKzXUJiewIDAQABAoIBAEcfQtZTaI56iX16yQ2UjR+w6/XWV5wBOqwYiH6sssuc4Bka6uI4cLmQrGMNgGO312buk9kHYukUCETi1AbZbU35xdsVlzaoVXDkoW4Yn3P5m5K6vwjB7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b71dQc+0LrESD5JJOfmmrlqbQ==`;

    // 设置公钥和私钥
    jsEncrypt.setPublicKey(publicKey);
    jsEncrypt.setPrivateKey(privateKey);

    // 明文步进
    let textStep = `这是测试内容一共十位`;
    // let textStep = `！@#￥%…&**（）{}：”`;
    // let textStep = `abcdefghij`;
    // let textStep = `0123456789`;

    // 要加密的明文
    let plaintext = "";
    for (let i = 0; i < 100; i++) {
      plaintext += textStep;
    }
    console.log("==== 明文长度: ====", plaintext?.length);
    // 加密数据
    const ciphertext = jsEncrypt.encryptLong(plaintext);
    console.log("==== 密文: ====", ciphertext);

    // 解密数据
    const decryptedText = jsEncrypt.decryptLong(ciphertext as string);
    console.log("==== 解密后的明文: ====", decryptedText);
    console.log("==== 解密后的明文长度: ====", decryptedText?.length);
  }, []);
  return <div className="app-container"></div>;
}

export default App;
